<div class="easyui-tabs" style="width: 250px; height: 200px" id='tt1'>

	<div title="部门" style="overflow: auto; padding: 10px;">
		<ul class="easyui-tree"
			url="../service/departments.php?defDep=<?php echo  $userVo->depID ?>"
			data-options="animate:true,checkbox:true,onlyLeafCheck:true"
			id="depID">

		</ul>
	</div>
	<div title="车系" style="overflow: auto; padding: 10px;">

		<ul class="easyui-tree"
			url="../service/vehicleNumber.php?defDep=<?php echo  $userVo->depID ?>"
			data-options="animate:true,checkbox:true,onlyLeafCheck:true"
			id="v_modelID">

		</ul>
	</div>

	<div title="客户" style="overflow: auto; padding: 10px;">

		<ul class="easyui-tree"
			url="../service/customer.php?defDep=<?php echo  $userVo->depID ?>"
			data-options="animate:true,checkbox:true,onlyLeafCheck:true"
			id="v_cusID">

		</ul>
	</div>

</div>


<div style="padding: 0px">
	<table id="dg" class="easyui-datagrid" title=""
		style="width: 250px; height: 270px"
        data-options="rownumbers:true,singleSelect:true,selectOnCheck:false,checkOnSelect:false,pagination:true">
		<thead>
			<tr>
				<th data-options="field:'licenseNumber',width:60">车牌号</th>
				<th data-options="field:'online',width:60,hidden:false">引擎状态</th>
				<th data-options="field:'d_esn',width:80,hidden:false">D_ESN</th>
				<th data-options="field:'address_num',width:80,hidden:true">地址</th>
				<th data-options="field:'latitude',width:50,hidden:true">latitude</th>
				<th data-options="field:'longitude',width:50,hidden:true">longitude</th>
				<th data-options="field:'time',width:100,hidden:true">时间</th>
				<th data-options="field:'vin',width:50,hidden:true">vin</th>
				<th data-options="field:'deviceID',width:100,hidden:true">deviceID</th>
				<th data-options="field:'heading',width:100,hidden:true">heading</th>
				<th data-options="field:'ign',width:100,hidden:true">ign</th>
			</tr>
		</thead>
	</table>

</div>

<script type="text/javascript">
	var seletedArr = new Array();

	$('#dg').datagrid({
		onCheckAll : function(rows) {
			//	alert(rows[0].d_esn);
			top.checkAll(rows);
		}

	});

	$('#dg').datagrid({
		onCheck : function(rowIndex, rowData) {
			top.onCheck(rowData);
		}

	});

	$('#dg').datagrid({
		onUncheck : function(rowIndex, rowData) {
			top.onUncheck(rowData);
		}

	});

	$('#dg').datagrid({
		onUncheckAll : function(rows) {
			//	alert(rows[0].d_esn);
			top.onUncheckAll(rows);
		}

	});

	$('#dg').datagrid({
		onDblClickRow : function(rowIndex, rowData) {
			//	alert("DbClick row "+rowData.d_esn);
			top.vehicleClick(rowData);
			//	$("#myid", top.document).;
			//	alert($("#updkbi", top.document).attr("value"));
		}
	});

	function getSelected() {
		var row = $('#dg').datagrid('getSelected');
		if (row) {
			$.messager.alert('Info', row.itemid + ":" + row.productid + ":"
					+ row.attr1);
		}
	}
	function getSelections() {
		var ss = [];
		var rows = $('#dg').datagrid('getSelections');
		for ( var i = 0; i < rows.length; i++) {
			var row = rows[i];
			ss.push('<span>' + row.itemid + ":" + row.productid + ":"
					+ row.attr1 + '</span>');
		}
		$.messager.alert('Info', ss.join('<br/>'));
	}

	//初始为根节点，从页面参数传入
	var depID = '<?php echo  $userVo->depID ?>';
	$('#depID')
			.tree(
					{
						onCheck : function(node, checked) {
							//	alert("check");
							seletedArr = new Array();
							var nodes = $('#depID').tree('getChecked');
							for (i = 0; i < nodes.length; i++) {
								seletedArr.push(nodes[i].id);
							}
							if (seletedArr.length == 0) {
								seletedArr.push(-1);
							}
							if (seletedArr.length > 0) {
								var tmp = seletedArr.join(",");
								//	 alert("tmp:"+tmp);
								$('#dg')
										.datagrid({
											loadFilter : pagerFilter
										})
										.datagrid(
												{
													url : '../service/vehicles4dep.php?searchType=0&deps='
															+ tmp
												});

							}
						}
					});

	$('#v_modelID')
			.tree(
					{
						onCheck : function(node, checked) {
							//	alert("check");
							seletedArr = new Array();
							var nodes = $('#v_modelID').tree('getChecked');
							for (i = 0; i < nodes.length; i++) {
								seletedArr.push(nodes[i].id);
							}
							if (seletedArr.length == 0) {
								seletedArr.push(-1);
							}
							if (seletedArr.length > 0) {
								var tmp = seletedArr.join(",");
								//	 alert("tmp:"+tmp);
								$('#dg')
										.datagrid({
											loadFilter : pagerFilter
										})
										.datagrid(
												{
													 url:'../service/vehicles4dep.php?searchType=1&models='+tmp+"&deps="+depID
												});

							}
						}
					});

	$('#v_cusID')
			.tree(
					{
						onCheck : function(node, checked) {
							//	alert("check");
							seletedArr = new Array();
							var nodes = $('#v_cusID').tree('getChecked');
							for (i = 0; i < nodes.length; i++) {
								seletedArr.push(nodes[i].id);
							}
							if (seletedArr.length == 0) {
								seletedArr.push(-1);
							}
							if (seletedArr.length > 0) {
								var tmp = seletedArr.join(",");
								//	 alert("tmp:"+tmp);
								$('#dg')
										.datagrid({
											loadFilter : pagerFilter
										})
										.datagrid(
												{
													 url:'../service/vehicles4dep.php?searchType=2&deps='+depID+"&cus="+tmp
												});

							}
						}
					});

	$('#tt1').tabs({
		onSelect : function(title, index) {
			tabIndex = index;

		}
	});

	$(document).ready(function() {
		//	var node = $('#depID').tree('find', 1070);
		//	$('#depID').tree('select', node.target);
	});

	function pagerFilter(data) {
		if (typeof data.length == 'number' && typeof data.splice == 'function') { // is array
			data = {
				total : data.length,
				rows : data
			}
		}
		var dg = $(this);
		var opts = dg.datagrid('options');
		var pager = dg.datagrid('getPager');
		pager.pagination({
			onSelectPage : function(pageNum, pageSize) {
				opts.pageNumber = pageNum;
				opts.pageSize = pageSize;
				pager.pagination('refresh', {
					pageNumber : pageNum,
					pageSize : pageSize
				});
				dg.datagrid('loadData', data);
			}
		});
		if (!data.originalRows) {
			data.originalRows = (data.rows);
		}
		var start = (opts.pageNumber - 1) * parseInt(opts.pageSize);
		var end = start + parseInt(opts.pageSize);
		data.rows = (data.originalRows.slice(start, end));
		return data;
	}
	
	 var tabIndex;
	 $('#tt1').tabs({
			onSelect: function(title,index){
				
				if(title != tabIndex){
					if(title=='部门'){
						$('#depID').tree('reload');
					}
					else if(title=='车系'){
						$('#v_modelID').tree('reload');
					}
                 else if(title=='客户'){
                 	$('# v_cusID').tree('reload');
					}
					
					$('#dg').datagrid('loadData',{total:0,rows:[]});
					
				}
             tabIndex=title;
			  }
			});
</script>